﻿using System;
using System.Drawing;
using System.Windows.Forms;
using ArcEngine.Graphics;


namespace ArcEngine.Input
{

	/// <summary>
	/// Mouse 
	/// </summary>
	public static class Mouse
	{

		#region Properties

		/// <summary>
		/// Gets/sets the mouse Offset
		/// </summary>
		public static Point Position
		{
			get
			{
				return Video.Form.PointToClient(Cursor.Position);
			}
			set
			{
				Cursor.Position = Video.Form.PointToScreen(value);
			}
		}


		/// <summary>
		/// Last known location
		/// </summary>
		static Point lastPostion = Point.Empty;


		/// <summary>
		///  Gets/sets the cursor visibility
		/// </summary>
		public static bool Visible
		{
			get
			{
				return visible;
			}
			set
			{
				visible = value;
				if (value)
					Cursor.Show();
				else
					Cursor.Hide();
			}
		}
		static bool visible;
 

		/// <summary>
		/// Gets and sets whether or not the mouse cursor is visible. 
		/// </summary>
		public static Cursor Cursor
		{
			get
			{
				return Video.Form.Cursor;
			}
			set
			{
				Video.Form.Cursor = value;
			}
		}


		/// <summary>
		/// Gets the mouse button states
		/// </summary>
		static public MouseButtons Buttons
		{
			get
			{
				return buttons;
			}
		}
		static MouseButtons buttons = new MouseButtons();

		#endregion


		#region Updaters

		/// <summary>
		/// ButtonDown event
		/// </summary>
		/// <param name="e"></param>
		internal static void ButtonDown(MouseEventArgs e)
		{
			buttons  ^= e.Button;

			if (OnButtonDown != null)
				OnButtonDown(null, e);
		}


		/// <summary>
		/// ButtonUp event
		/// </summary>
		/// <param name="e"></param>
		internal static void ButtonUp(MouseEventArgs e)
		{
			buttons ^= e.Button;

			if (OnButtonUp != null)
				OnButtonUp(null, e);
		}


		/// <summary>
		/// Move event
		/// </summary>
		/// <param name="e"></param>
		internal static void Move(MouseEventArgs e)
		{
			lastPostion = e.Location;

			if (OnMove != null)
				OnMove(null, e);
		}


		/// <summary>
		/// DoubleClick event
		/// </summary>
		/// <param name="e"></param>
		internal static void DoubleClick(MouseEventArgs e)
		{
			if (OnDoubleClick != null)
				OnDoubleClick(null, e);
		}

		#endregion


		#region Events
		/// <summary>
		///  Event fired when a ButtonDown occur
		/// </summary>
		public static event EventHandler<MouseEventArgs> OnButtonDown;


		/// <summary>
		/// Event fired when a ButtonUp occurs
		/// </summary>
		public static event EventHandler<MouseEventArgs> OnButtonUp;

		/// <summary>
		/// Event fired when a mouse move occurs
		/// </summary>
		public static event EventHandler<MouseEventArgs> OnMove;

		/// <summary>
		/// Event fired when a double click occurs
		/// </summary>
		public static event EventHandler<MouseEventArgs> OnDoubleClick;

		#endregion



 
         


	}



}
